/*
 * Created on Feb 12, 2004
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package dbsucxentW.storageW.entitiesW;

import java.io.Serializable;

/**
 * This class stores the value of a leaf node
 */
public class LeafNode implements Serializable {
    // <editor-fold desc="Leaf Order">
    private int _order;

    public int getOrder() {
        return _order;
    }

    public void setOrder(int order) {
        _order = order;
    }
    // </editor-fold>
    // <editor-fold desc="Branch Order">
    private int _branchOrder;

    public int getBranchOrder() {
        return _branchOrder;
    }

    public void setBranchOrder(int branchOrder) {
        _branchOrder = branchOrder;
    }
    // </editor-fold>
    // <editor-fold desc="Ancestor DeweyGroup">
    private long ancestorDeweyGroup;

    public long getAncestorDeweyGroup() {
        return ancestorDeweyGroup;
    }

    public void setAncestorDeweyGroup(long ancestorDeweyGroup) {
        this.ancestorDeweyGroup = ancestorDeweyGroup;
    }
    // </editor-fold>
    // <editor-fold desc="Sibling Sum">
    private long _siblingSum;
    public long getSiblingSum() {
        return _siblingSum;
    }

    public void setSiblingSum(long siblingSum) {
        _siblingSum = siblingSum;
    }
    // </editor-fold>
    // <editor-fold desc="Path">
    private String _path;
    public String getPath() {
        return _path;
    }

    public void setPath(String path) {
        _path = path;
    }
    // </editor-fold>
    // <editor-fold desc="Path ID">
    private int _pathId;
    public int getPathId() {
        return _pathId;
    }

    public void setPathId(int pathId) {
        _pathId = pathId;
    }
    // </editor-fold>
    // <editor-fold desc="Doc ID">
    private int _docId = -1;// = 1; //klarinda 20060904 hardcode docId for experiment purpose

    public int getDocId() {
        return _docId;
    }

    public void setDocId(int docId) {
        _docId = docId;
    }
    // </editor-fold>
    // <editor-fold desc="Is Attribute">
    private boolean _isAttribute = false;	//klarinda 20060831 - to separate attribute table
    
    public boolean getIsAttribute() {
        return _isAttribute;
    }

    public void setIsAttribute(boolean isAttr) {
        _isAttribute = isAttr;
    }
    // </editor-fold>
    // <editor-fold desc="Is Large Text Data">
    private boolean _isLargeTextData = false;	//klarinda 20070525 - add TextContent

    //klarinda 20070525 - add TextContent table
    public void setIsLargeTextData(boolean tc) {
        _isLargeTextData = tc;
    }
    public boolean getIsLargeTextData() {
        return _isLargeTextData;
    }
    // </editor-fold>
    // <editor-fold desc="Value">
    private StringBuilder _valueBuilder = new StringBuilder();

    public String getValue() {
        String value;
        if (_valueBuilder.length() < 512) {
            value = _valueBuilder.toString();
        } else {
            value = _valueBuilder.substring(0, 500);
        }
        value = value.replace('\n', ' ');
        return value;
    }

    public void setValue(String value) {
        _valueBuilder.append(value);
        escapeSql();
    }

    protected void escapeSql() {
        String value;
        value = _valueBuilder.toString();
        value = value.replace("'", "''");
        _valueBuilder = new StringBuilder();
        _valueBuilder.append(value);
    }
    // </editor-fold>

    //klarinda 20060904 bulk loading
    //return the string of element leaf node
    public String bulkLoad() {
        String sql;
        if (_isLargeTextData) //k20070525 add TextContent
        {
            sql = _docId + "\t" + _order + "\t" + _branchOrder + "\t" + _pathId + "\t"
                    + ancestorDeweyGroup + "\t" + _siblingSum + "\t" + "";
        } else {
            sql = _docId + "\t" + _order + "\t" + _branchOrder + "\t" + _pathId + "\t"
                    + ancestorDeweyGroup + "\t" + _siblingSum + "\t" + getValue();
        }
        return sql;
    }

    //return the string of attribute node
    public String bulkLoadAttribute() {
        String sql;
        if (_isLargeTextData) //k20070525 add AttrContent
        {
            sql = _docId + "\t" + ancestorDeweyGroup + "\t" + _pathId + "\t" + "";
        } else {
            sql = _docId + "\t" + ancestorDeweyGroup + "\t" + _pathId + "\t" + _valueBuilder.toString();
        }
        return sql;
    }

    //return the string of element leaf node (k20070525 add TextContent)
    public String bulkLoadTextContent() {
        String sql;
        sql = _docId + "\t" + _order + "\t" + _branchOrder + "\t" + _pathId + "\t"
                + ancestorDeweyGroup + "\t" + _siblingSum + "\t" + _valueBuilder.toString();
        return sql;
    }

    //return the string of attribute node (k20070525 add AttrContent)
    public String bulkLoadAttrContent() {
        String sql;
        sql = _docId + "\t" + ancestorDeweyGroup + "\t" + _pathId + "\t" + _valueBuilder.toString();
        return sql;
    }
    //end of klarinda
}
